package com.hhit.zhgd.utils

import com.hhit.zhgd.domain.entity.LoginLog
import org.junit.jupiter.api.Test
import java.util.*
import kotlin.collections.ArrayList
import kotlin.collections.LinkedHashMap

class KotlinStreamTests {

    @Test
    fun objectToMap() {
        val loginLogs = ArrayList<LoginLog>().also {
            it.add(LoginLog(id = 1, adminId = 1, loginIp = "127.0.0.1", createTime = Date()))
            it.add(LoginLog(id = 2, adminId = 1, loginIp = "127.0.0.1", createTime = Date()))
            it.add(LoginLog(id = 3, adminId = 2, loginIp = "127.0.0.1", createTime = Date()))
            it.add(LoginLog(id = 4, adminId = 2, loginIp = "127.0.0.1", createTime = Date()))
            it.add(LoginLog(id = 5, adminId = 3, loginIp = "127.0.0.1", createTime = Date()))
            it.add(LoginLog(id = 6, adminId = 4, loginIp = "127.0.0.1", createTime = Date()))
            it.add(LoginLog(id = 7, adminId = 4, loginIp = "127.0.0.1", createTime = Date()))
            it.add(LoginLog(id = 8, adminId = 4, loginIp = "127.0.0.1", createTime = Date()))
            it.add(LoginLog(id = 9, adminId = 4, loginIp = "127.0.0.1", createTime = Date()))
        }

        val result = loginLogs.map { it.adminId }.toList()
        result.forEach { println(it) }


        val result1 = loginLogs.groupBy { it.adminId }.mapValues { it.value.toCollection(mutableListOf()) }.toMap(LinkedHashMap())
        result1.forEach { (t, u) ->
            println("key:$t")
            u.forEach {
                println("value:$it")
            }
        }
    }
}